package com.turing.usdtpay.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.turing.usdtpay.R;
import com.turing.usdtpay.entity.StreamData;
import com.turing.usdtpay.utils.FormatUtils;

import java.util.List;

/**
 * @作者：JAY
 * @创建时间：2019/10/15 16:31
 * @描述：
 **/
public class CommissionAdapter extends RecyclerView.Adapter<CommissionAdapter.Holder>{
    private Context mContext;
    private List<StreamData> mStreamDataList;
    private Holder holder;
    private OnClickStream mOnClickListener;

    public CommissionAdapter(Context context, List<StreamData> streamDataList) {
        this.mContext = context;
        this.mStreamDataList = streamDataList;
    }

    @Override
    public Holder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(mContext).inflate(R.layout.item_commission, parent, false);
        holder = new Holder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(Holder holder, int position) {
        StreamData data = mStreamDataList.get(position);
        holder.mName.setText(data.getName());
        holder.mProbability.setText(data.getProbability()+"%");
        holder.mCNY.setText(FormatUtils.NoumberFromat2(data.getCny()));
        holder.mCount.setText(FormatUtils.NoumberFromat2(data.getCount()));
        holder.mTrade.setText(FormatUtils.NoumberFromat2(data.getTrade()));
        holder.mReady.setText(FormatUtils.NoumberFromat2(data.getReady()));
        if (data.getType() == 1){
            holder.mCNYLayout.setVisibility(View.VISIBLE);
            holder.mCountLayout.setVisibility(View.VISIBLE);
            holder.mTradeLayout.setVisibility(View.VISIBLE);
            holder.mSteamLayout.setVisibility(View.VISIBLE);
            holder.mReadyLayout.setVisibility(View.GONE);
            holder.mEmptyLayout.setVisibility(View.GONE);
        }else if (data.getType() == 2){
            holder.mCNYLayout.setVisibility(View.VISIBLE);
            holder.mCountLayout.setVisibility(View.VISIBLE);
            holder.mTradeLayout.setVisibility(View.VISIBLE);
            holder.mReadyLayout.setVisibility(View.GONE);
            holder.mSteamLayout.setVisibility(View.GONE);
            holder.mEmptyLayout.setVisibility(View.GONE);
        } else if (data.getType() == 3){
            holder.mCNYLayout.setVisibility(View.VISIBLE);
            holder.mCountLayout.setVisibility(View.VISIBLE);
            holder.mTradeLayout.setVisibility(View.VISIBLE);
            holder.mReadyLayout.setVisibility(View.GONE);
            holder.mSteamLayout.setVisibility(View.GONE);
            holder.mEmptyLayout.setVisibility(View.GONE);
        }else if (data.getType() == 4){
            holder.mCNYLayout.setVisibility(View.VISIBLE);
            holder.mCountLayout.setVisibility(View.GONE);
            holder.mTradeLayout.setVisibility(View.GONE);
            holder.mReadyLayout.setVisibility(View.VISIBLE);
            holder.mEmptyLayout.setVisibility(View.VISIBLE);
            holder.mSteamLayout.setVisibility(View.GONE);
        }
        holder.mSteamLayout.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (mOnClickListener != null){
                    mOnClickListener.onClick();
                }
            }
        });
    }

    public void setOnClickListener(OnClickStream mOnClickListener) {
        this.mOnClickListener = mOnClickListener;
    }

    @Override
    public int getItemCount() {
        return mStreamDataList.size();
    }

    public interface OnClickStream{
        public void onClick();
    }

    public void updataData(List<StreamData> list){
        mStreamDataList = list;
        notifyDataSetChanged();
    }

    public class Holder extends RecyclerView.ViewHolder{

        private TextView mName,mProbability,mCNY,mCount,mTrade,mReady;
        private LinearLayout mSteamLayout,mCNYLayout,mCountLayout,mTradeLayout,mReadyLayout,mEmptyLayout;
        public Holder(View itemView) {
            super(itemView);
            mName = (TextView) itemView.findViewById(R.id.item_name);
            mProbability = (TextView) itemView.findViewById(R.id.item_probability);
            mCNY = (TextView) itemView.findViewById(R.id.item_cny);
            mCount = (TextView) itemView.findViewById(R.id.item_count);
            mTrade = (TextView) itemView.findViewById(R.id.item_trade);
            mReady = (TextView) itemView.findViewById(R.id.item_ready);
            mSteamLayout = (LinearLayout) itemView.findViewById(R.id.steam_layout);
            mCNYLayout = (LinearLayout) itemView.findViewById(R.id.cny_layout);
            mCountLayout = (LinearLayout) itemView.findViewById(R.id.count_layout);
            mTradeLayout = (LinearLayout) itemView.findViewById(R.id.trade_layout);
            mReadyLayout = (LinearLayout) itemView.findViewById(R.id.ready_layout);
            mEmptyLayout = (LinearLayout) itemView.findViewById(R.id.empty_layout);
        }
    }
}
